namespace Asmex.FileViewer
{
    using Asmex.ObjViewer;
    using System;
    using System.IO;

    public class MDStreamHeader : Region
    {
        private string _Name;
        private uint _Offset;
        private uint _Size;
        private StreamType _Type;

        public MDStreamHeader(BinaryReader reader)
        {
            base.Start = reader.BaseStream.Position;
            this._Offset = reader.ReadUInt32();
            this._Size = reader.ReadUInt32();
            char[] chArray = new char[0x20];
            int num = 0;
            byte num2 = 0;
            while ((num2 = reader.ReadByte()) != 0)
            {
                chArray[num++] = (char) num2;
            }
            num++;
            int count = ((num % 4) != 0) ? (4 - (num % 4)) : 0;
            reader.ReadBytes(count);
            this._Name = new string(chArray).Trim(new char[1]);
            if (this.Name == "#Strings")
            {
                this._Type = StreamType.StrType;
            }
            else if ((this.Name == "#US") || (this.Name == "#Blob"))
            {
                this._Type = StreamType.BlobType;
            }
            else if (this.Name == "#GUID")
            {
                this._Type = StreamType.GUIDType;
            }
            else
            {
                this._Type = StreamType.TableType;
            }
            base.Length = reader.BaseStream.Position - base.Start;
        }

        public string Name
        {
            get
            {
                return this._Name;
            }
        }

        [ObjViewer(Hex=true)]
        public uint Offset
        {
            get
            {
                return this._Offset;
            }
        }

        [ObjViewer(Hex=true)]
        public uint Size
        {
            get
            {
                return this._Size;
            }
        }

        public StreamType Type
        {
            get
            {
                return this._Type;
            }
        }

        public enum StreamType
        {
            StrType,
            BlobType,
            GUIDType,
            TableType
        }
    }
}
